package com.ruoyi.oto.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.oto.domain.vo.NewsVO;
import com.ruoyi.oto.task.OTOTask;
import com.ruoyi.system.service.ISysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

/**
 * 小程序-新闻列表
 */
@RestController
@RequestMapping("/api/v2/news")
public class NewsApiController extends BaseController {

    @Autowired
    private RedisCache redisCache;

    @Autowired
    private OTOTask task;
    /**
     * 获取最新的三条新闻快照
     * @return
     */
    @GetMapping("/getNewsSnapshot")
    public AjaxResult<List<NewsVO>> getNewsSnapshot() {
        return AjaxResult.success(redisCache.getCacheList("newsList"));
    }

    /**
     * 触发获取新闻快照
     * @return
     */
    @GetMapping("/trigger")
    public AjaxResult<?> trigger() throws IOException {
        task.geJXNews();
        return AjaxResult.success();
    }

}
